package generator;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;

public class CodeGenerator {
    private static  String URL = "jdbc:mysql://localhost:3306/random";
    private static  String USERNAME = "root";
    private static  String PASSWORD = "root";

    private static  String AUTHOR = "wiken";

    private static  String BASEPATH = "E:\\实战项目\\random-parent\\service\\";

    private static  String OUTPATH = "\\src\\main\\java";
    private static String module = "store-service";
    private static String table = "user_store_activity";

    public static void main(String[] args) {
        String[] split = module.split("-");
        String moduleName = "";

        Iterator<String> iterator = Arrays.stream(split).iterator();
        while(iterator.hasNext()) moduleName += iterator.next();

        String finalModuleName = moduleName;
        FastAutoGenerator.create(URL, USERNAME, PASSWORD)
                .globalConfig(builder -> {
                    builder.author(AUTHOR) // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir(BASEPATH + module + OUTPATH); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.wiken") // 设置父包名
                            .moduleName(finalModuleName) // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "E:\\实战项目\\random-parent\\service\\store-service\\src\\main\\java\\mapper\\xml")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude(table); // 设置需要生成的表名
//                            .addTablePrefix("t_", "c_"); // 设置过滤表前缀
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
